<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p>例如：求出这个字符串'abAAbcBCCccdaACBDDabcccddddaab'中出现最多的字母,并求出出现多少次(忽略大小写)。
        var str = 'abbbbAAbcBCCccdaACBDDabcccddddaab';
        </p>
    <script>
        //这是正则处理的
        var str = 'abbbbAAbcBCCccdaACBDDabcccddddaab';
    str = str.toLowerCase().split('').sort(function(a,b){return a.localeCompare(b)}).join('');

    var reg = /(\w)\1+/ig;
    var maxStr = '';
    var maxLen = 0;
    str.replace(reg,function($0,$1){
        var regLen = $0.length;
        if(regLen>maxLen){
            maxLen = regLen;
            maxStr = $1;
        }else if(maxLen == regLen){
            maxStr += $1;
        }
    })
    // console.log(`出现最多的字母是${maxStr},共出现了${maxLen}次`)

    //-----------------------------------
    //这个是用es6的reduce来处理
   var strs = 'abbbbAAbcBCCccdaACBDDabcccddddaab'; 
   var strsb = strs.toLowerCase().split('');
//    console.log(strsb)
   var ak = strsb.reduce(function(pre,cur) {    
       pre[cur]?pre[cur]++:pre[cur]=1; 
    //    console.log(pre)
       
       return pre;
    },{})
   console.log('这个reduce上面会返回新的数组的,length等于0')
   console.log(ak)
   
   var arr = []
   Object.keys(ak).forEach(item => {
    let objs = {};
    console.log(item)
    objs[item] = ak[item];//键值对匹配
    arr.push(objs)
});

console.log(arr);

    </script>
</body>
</html>